package top.lyc829.zzl_android.ui.profile.follow.base;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.chad.library.adapter.base.module.LoadMoreModule;

import java.io.IOException;
import java.util.List;

import okhttp3.Response;
import top.lyc829.zzl_android.logic.bean.BaseBean;
import top.lyc829.zzl_android.logic.bean.ResultBean;
import top.lyc829.zzl_android.logic.network.Network;
import top.lyc829.zzl_android.logic.util.HttpUtil;
import top.lyc829.zzl_android.logic.util.Utils;
import top.lyc829.zzl_android.logic.util.gson.JsonUtilNew;

public class FollowBaseViewModel extends ViewModel  {
    // TODO: Implement the ViewModel

    private MutableLiveData<List<BaseBean>> followBaseLiveData;
//alt+inset;  get
    public MutableLiveData<List<BaseBean>> getFollowBaseLiveData() {
        if (followBaseLiveData == null)
        {
            //实例化
            followBaseLiveData=new MutableLiveData<>();
        }
        return followBaseLiveData;
    }


    public void getFollowBaseList(int userId)
    {
        Network.getFollowBaseList(userId, new HttpUtil.MyCallback() {
            @Override
            public void success(Response res) throws IOException {
                String resultStr=res.body().string();

                ResultBean<List<BaseBean>> resultBean = JsonUtilNew.fromJsonArray(resultStr, BaseBean.class);
                if(resultBean.getCode().equals(200))
                {
                    getFollowBaseLiveData().postValue(resultBean.getData());

                }
                else {
                    failed(new IOException(resultBean.getMsg()));
                }
            }

            @Override
            public void failed(IOException e) {
                getFollowBaseLiveData().postValue(null);
                Utils.Sout(e.getMessage());
            }
        });
    }

}